/*
 * @Description: SyncLoopHook 遇到有返回值时, 会重新执行该回调函数, 直到返回为undefined, 则进入下一个tap
 * @Author: wangqi
 * @Date: 2021-04-17 11:59:14
 * @LastEditTime: 2021-04-17 22:46:04
 */

// 循环函数，可用来处理需要重复执行的函数
let { SyncLoopHook } = require('tapable');

class Lesson {
    constructor() {
        this.index = 0;
        this.hook = {
            arch: new SyncLoopHook(['name', 'age']),
        }
    }

    tap() {
        this.hook.arch.tap('node', (...res) => {
            console.log("来自外部传入|", ...res)
            let obj = { "state": 'node学的不错' }
            if (++this.index === 3) {
                this.index = 0;
                return undefined;
            } else {
                return '继续学'
            }
        });

        this.hook.arch.tap('vue', (...res) => {
            console.log("来自node|2", ...res)
            let obj = { "state": 'vue也不错' }
            // return obj
        });
        this.hook.arch.tap('react', (...res) => {
            console.log("来自vue|3", ...res)
            let obj = { "state": 'react也不错' }
            // return ++this.index === 3 ? undefined : '继续学1';

        });
    }

    start() {
        this.hook.arch.call('wq', '12')
    }
}

let lesson = new Lesson();

lesson.tap();
lesson.start();
